package com.jiajiankang.myspace;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.TextView;

import com.jiajiankang.R;

public class AllOrderAdapter extends BaseAdapter {
	private List<Map<String, Object>> mAppList;
	private LayoutInflater mInflater;
	private Context mContext;

	private MyHolder holder;
	final int TYPE_1 = 0;
	final int TYPE_2 = 1;

	public AllOrderAdapter(Context c, List<Map<String, Object>> appList) {

		mAppList = appList;
		mContext = c;
		mInflater = (LayoutInflater) mContext
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

	}

	public class MyHolder {
		TextView tv1;
		TextView tv2;
		TextView tv3;
		TextView tv4;
		ImageButton ibtn1;
	}

	@Override
	public int getItemViewType(int position) {
		// TODO Auto-generated method stub

		int p = position % 2;
		if (p == 0)
			return TYPE_1;
		else
			return TYPE_2;

	}

	@Override
	public int getViewTypeCount() {
		// TODO Auto-generated method stub
		return 2;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mAppList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mAppList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub

		return mAppList.size();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		MyHolder holder1 = new MyHolder();
		MyHolder holder2 = new MyHolder();
		int type = getItemViewType(position);
		if (convertView != null) {
			holder = (MyHolder) convertView.getTag();

			switch (type) {
			case TYPE_1:
				holder1 = (MyHolder) convertView.getTag();
				break;
			case TYPE_2:
				holder2 = (MyHolder) convertView.getTag();
				break;

			}

		} else {
			switch (type) {
			case TYPE_1:

				convertView = mInflater.inflate(R.layout.waitdeliver_list, null);

				holder1.tv1 = (TextView) convertView
						.findViewById(R.id.waitdeliver_list_order_number);
				holder1.tv2 = (TextView) convertView
						.findViewById(R.id.waitdeliver_list_order_value);
				holder1.tv3 = (TextView) convertView
						.findViewById(R.id.waitdeliver_list_order_time);
				holder1.tv4 = (TextView) convertView
						.findViewById(R.id.waitdeliver_list_get_number);
				convertView.setTag(holder);
				break;
			case TYPE_2:

				convertView = mInflater.inflate(R.layout.waitpay_list, null);
				holder2.tv1 = (TextView) convertView
						.findViewById(R.id.waitpay_order_number);
				holder2.tv2 = (TextView) convertView
						.findViewById(R.id.waitpay_order_value);
				holder2.tv3 = (TextView) convertView
						.findViewById(R.id.waitpay_order_time);
			
				convertView.setTag(holder);

				break;
			}
		}

		Map<String, Object> appInfo = mAppList.get(position);
		if (appInfo != null) {
			switch (type) {
			case TYPE_1:
				// holder1 . tv1. setText ((String ) appInfo. get(
				// "order_number" ));break;
				holder1.tv1.setText("123");
				break;

			case TYPE_2:
				holder2.tv1.setText("456");
				break;
			}
		}

		return convertView;

	}
}
